﻿/*
 * Erstellt mit SharpDevelop.
 * Benutzer: Kai Patrick
 * Datum: 31.03.2008
 * Zeit: 20:14
 * 
 * Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern.
 */

using System;
using Gamadus.Builder;

namespace Gamadus.Builder.Ast
{
	/// <summary>
	/// Description of Expression.
	/// </summary>
	public abstract class Expression : GmlNode
	{
		public Expression(Irony.Compiler.AstNode node, SourceLocation location) : base(node, location)
		{
		}
		
		public static Expression MakeExpression(Irony.Compiler.AstNode node, SourceLocation location)
		{
			switch(node.Term.Name)
			{
				case "String":
				case "number":
					return new Constant(node, location);
				case "Identifier":
					return new Named(node, location);
				case "Expr":
					if(node.ChildNodes.Count == 3)
						return new Binary(node, location);
					else
						throw new NotImplementedException();
				case "FunctionExpression":
					return new Function(node, location);
				default:
					throw new ArgumentException("Invalid expression: "+node.Term.Name);
			}
		}
		
		public abstract string Generate();
		
//		internal protected abstract MSAst.Expression Generate();
//		
//		internal protected virtual MSAst.Expression GenerateAssign(MSAst.Expression right) {
//            throw new System.InvalidOperationException("Assignment to non-lvalue");
//        }
	}
}
